package offer;

import java.util.LinkedList;

public class offerII_0041 {
    class MovingAverage {
        int sum=0;
        int size=0;
        int current=0;
        LinkedList<Integer> list=new LinkedList<>();
        /** Initialize your data structure here. */
        public MovingAverage(int size) {
            this.size=size;

        }

        public double next(int val) {
            if(current<size){
                list.add(val);
                current++;
                sum+=val;
                return sum/(double) current;
            }
            else{
                sum-=list.removeFirst();
                sum+=val;
                list.add(val);
                return sum/(double) size;
            }
        }
    }
}
